package com.xywy.beautyand.base;



import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.xywy.beautyand.R;
import com.xywy.beautyand.util.DeviceUtil;
import com.xywy.beautyand.util.NetUtil;
import com.xywy.beautyand.util.UIUtil;
import com.xywy.beautyand.vollery.BaseRequest;
import com.xywy.beautyand.vollery.VolleyManager;

/**
 ****************************************** 
 * @Title: BaseAct.java
 * @Package com.xywy.bloodandroid.base
 * @Description: TODO(activity�Ļ���)
 * @author smz
 * @date 2014-12-23 ����10:21:21
 * @version V1.0
 ******************************************* 
 */
public abstract class BaseActivity extends Activity implements OnClickListener {

	public static int deviceWidth = 0;
	public static int deviceHeight = 0;

	public static Context context;
	private ImageView left_img;
	private  TextView middle_title;
	private LinearLayout tobar;
	private ImageView right_img;
	protected  ProgressDialog waittingDialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initBase();
		initView(savedInstanceState);
		initListener();
		initData();
	}
	
	private void initBase() {
		context = this;
		if (deviceWidth == 0)
			deviceWidth = DeviceUtil.getDeviceWidth(this);
		if (deviceHeight == 0)
			deviceHeight = DeviceUtil.getDeviceHeight(this);

	}
	
	
	protected abstract void initView(Bundle savedInstanceState);
	protected abstract void initListener();
	protected abstract void initData();
  
	 public   void waitingDialog(Context context,String message) {
			if (waittingDialog == null)
				waittingDialog = new ProgressDialog(context);
			 waittingDialog.setCanceledOnTouchOutside(false);//�����಻��ʧ
			waittingDialog.setMessage(message);
			waittingDialog.show();
		}
	 
	 

		/**
		 * 
		 * 
		 * @param request
		 * @return
		 */
		protected boolean executeRequest(BaseRequest<?> request) {
			if (NetUtil.hasNetwork(context)) {
				waitingDialog(context, getResources().getString(R.string.request));
				VolleyManager.addRequest(request, this);
				return true;
			} else {
				UIUtil.showToast(context, getResources().getString(R.string.not_network));
				UIUtil.DissDialog(context, waittingDialog);
				return false;
			}
		}
	 
	  /**
	   * 不懈怠参�?
	   * @param clazz
	   */
		protected void enterActivity(Class<?> clazz) {
			startActivity(new Intent(this, clazz));
		}
       /**
        * 携带参数
        * @param clazz
        * @param bundle
        */
		protected void enterActivity(Class<?> clazz, Bundle bundle) {
			Intent intent = new Intent(this, clazz);
			intent.putExtras(bundle);
			startActivity(intent);
		}
		@Override
		public void onClick(View arg0) {
			
		}
}
